package com.xbn.xbnmall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author XBN
 * @date 2020/7/28 10:05
 * @email 78742541@qq.com
 */
@Configuration
public class ElasticConfig {
    public static final RequestOptions COMMON_OPITIONS;
    static {
        RequestOptions.Builder builder=RequestOptions.DEFAULT.toBuilder();
        COMMON_OPITIONS=builder.build();
    }
    /*创建es客户端*/
    @Bean
    public RestHighLevelClient esRestClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                //多个es可以指定多个
                RestClient.builder(
                        new HttpHost("localhost", 9200, "http")
                   /*    , new HttpHost("localhost", 9201, "http")*/
                )
        );
        return client;
    }
}
